<style lang="less">
    @import "../../../styles/table.less";
</style>
<template>
    <div class="search">
        <Row>
            <Col>
                <Card>
                    <Row @keydown.enter.native="handleSearch">
                        <Form ref="searchForm" :model="searchForm" inline :label-width="70">
                            <Form-item label="手机号" prop="id">
                                <Input type="text" v-model="searchForm.mobile" placeholder="请输入手机号" clearable style="width: 200px"/>
                            </Form-item>
                            <Form-item label="用户名称" prop="userName">
                                <Input type="text" v-model="searchForm.userName" placeholder="请输用户名称" clearable style="width: 200px"/>
                            </Form-item>
                            <span v-if="drop">
                                <Form-item label="审核状态" prop="isPass">
                                    <Select v-model="searchForm.isPass" placeholder="请选择" clearable style="width: 200px">
                                        <Option value="0">待审核</Option>
                                        <Option value="1">审核通过</Option>
                                        <Option value="2">审核拒绝</Option>
                                    </Select>
                                </Form-item>
                            </span>
                            <Form-item style="margin-left:-35px;" class="br">
                                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                                <Button @click="handleReset">重置</Button>
                                <a class="drop-down" @click="dropDown">{{dropDownContent}}
                                    <Icon :type="dropDownIcon"></Icon>
                                </a>
                            </Form-item>
                        </Form>
                    </Row>
                    <Row class="operation">
                        <Button @click="exportData" icon="md-trash">导出</Button>
                        <Button @click="getDataList" icon="md-refresh">刷新</Button>
                        <circleLoading v-if="operationLoading"/>
                    </Row>
                    <Row>
                        <Alert show-icon>
                            已选择 <span class="select-count">{{selectCount}}</span> 项
                            <a class="select-clear" @click="clearSelectAll">清空</a>
                        </Alert>
                    </Row>
                    <Row>
                        <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
                    </Row>
                </Card>
            </Col>
        </Row>
        <Modal v-model="picVisible" title="图片" draggable>
            <img :src="fileUrl" alt="无效的图片链接" style="width: 100%;margin: 0 auto;display: block;">
        </Modal>
        <creditbank-drawer ref="creditbankDrawer"></creditbank-drawer>
    </div>
</template>

<script>
    import circleLoading from "../../my-components/circle-loading.vue";
    import {creditbankList} from "@/api/bus";
    import Util from '@/libs/util';
    import creditbankDrawer from "./creditbank-drawer";

    export default {
        name: "creditbank-manage",
        components: {
            circleLoading,
            creditbankDrawer
        },
        data() {
            return {
                loading: false, // 表单加载状态
                operationLoading: false,
                drop: false,
                selectCount: 0, // 多选计数
                selectList: [], // 多选数据
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                fileUrl: "",
                picVisible: false,
                searchForm: {
                    pageNumber: 1, // 当前页数
                    pageSize: 10, // 页面大小
                    sort: "createTime", // 默认排序字段
                    order: "desc", // 默认排序方式
                    id: "",
                    isPass: "",
                    userName: "",
                    mobile: "",
                    startDate: "",
                    endDate: ""
                },
                selectDate: null, //选择日期绑定modal
                columns: [
                    {
                        type: "selection",
                        width: 60,
                        align: "center"
                    },
                    {
                        type: "index",
                        width: 60,
                        align: "center"
                    },
                    {
                        title: "姓名",
                        key: "userName",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "性别",
                        key: "sex",
                        width: 70,
                        align: "center",
                        render: (h, params) => {
                            let re = "";
                            if (params.row.sex === 1) {
                                re = "男";
                            } else if (params.row.sex === 2) {
                                re = "女";
                            }
                            return h("div", re);
                        }
                    },
                    {
                        title: "出生年月",
                        key: "birthday",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "手机号",
                        key: "mobile",
                        width: 120,
                        sortable: true
                    },
                    {
                        title: "证件号码",
                        key: "cardNo",
                        width: 170,
                        sortable: true
                    },
                    {
                        title: "身份证正面",
                        key: "cardFront",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            if(params.row.cardFront.length>0){
                                return h("img", {
                                    attrs: {
                                        src: params.row.cardFront,
                                        alt: "加载图片失败"
                                    },
                                    style: {
                                        cursor: "pointer",
                                        width: "80px",
                                        height: "60px",
                                        margin: "3px 0",
                                        "object-fit": "contain"
                                    },
                                    on: {
                                        click: () => {
                                            this.showPic(params.row.cardFront);
                                        }
                                    }
                                });
                            }else{
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "red"
                                            }
                                        },
                                        "未上传"
                                    )
                                ]);
                            }
                        }
                    },
                    {
                        title: "身份证背面",
                        key: "cardReverse",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            if(params.row.cardReverse.length>0){
                                return h("img", {
                                    attrs: {
                                        src: params.row.cardReverse,
                                        alt: "加载图片失败"
                                    },
                                    style: {
                                        cursor: "pointer",
                                        width: "80px",
                                        height: "60px",
                                        margin: "3px 0",
                                        "object-fit": "contain"
                                    },
                                    on: {
                                        click: () => {
                                            this.showPic(params.row.cardReverse);
                                        }
                                    }
                                });
                            }else{
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "red"
                                            }
                                        },
                                        "未上传"
                                    )
                                ]);
                            }
                        }
                    },
                    {
                        title: "国籍",
                        key: "nationalityName",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "民族",
                        key: "nationName",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "政治面貌",
                        key: "polStatusName",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "教育程度",
                        key: "eduDegreeName",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "学号",
                        key: "studentNo",
                        width: 180,
                        sortable: true
                    },
                    {
                        title: "城市",
                        key: "areaName",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "工作单位",
                        key: "company",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "部门",
                        key: "deptName",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "职务/岗位",
                        key: "positionName",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "职称",
                        key: "profTitle",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "行业类型",
                        key: "trade",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "固定电话",
                        key: "phone",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "QQ号",
                        key: "qq",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "电子邮箱",
                        key: "email",
                        width: 130,
                        sortable: true
                    },
                    {
                        title: "邮编",
                        key: "postcode",
                        width: 100,
                        sortable: true
                    },
                    {
                        title: "通讯地址",
                        key: "address",
                        width: 180,
                        sortable: true
                    },
                    {
                        title: "证书编号",
                        key: "credentialNo",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "颁证时间",
                        key: "credentialTime",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "培训机构",
                        key: "training",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "考试机构",
                        key: "examOrg",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "截止日期",
                        key: "deadline",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "证书",
                        key: "credentialImg",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            if(params.row.credentialImg.length){
                                return h("img", {
                                    attrs: {
                                        src: params.row.credentialImg,
                                        alt: "加载图片失败"
                                    },
                                    style: {
                                        cursor: "pointer",
                                        width: "80px",
                                        height: "60px",
                                        margin: "3px 0",
                                        "object-fit": "contain"
                                    },
                                    on: {
                                        click: () => {
                                            this.showPic(params.row.credentialImg);
                                        }
                                    }
                                });
                            }else{
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "red"
                                            }
                                        },
                                        "未上传"
                                    )
                                ]);
                            }
                        }
                    },
                    {
                        title: "审核状态",
                        key: "isPass",
                        align: "center",
                        width: 130,
                        render: (h, params) => {
                            let re = "";
                            if (params.row.isPass === 1) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "green"
                                            }
                                        },
                                        "审核通过"
                                    )
                                ]);
                            } else if (params.row.isPass === 2) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "red"
                                            }
                                        },
                                        "审核拒绝"
                                    )
                                ]);
                            }else if (params.row.isPass === 0) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "blue"
                                            }
                                        },
                                        "待审核"
                                    )
                                ]);
                            }
                        }
                    },
                    {
                        title: "审核意见",
                        key: "opinion",
                        width: 150,
                        sortable: true
                    },
                    {
                        title: "操作",
                        key: "action",
                        width: 150,
                        align: "center",
                        fixed: "right",
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Button",
                                    {
                                        props: {
                                            type: "error",
                                            size: "small"
                                        },
                                        on: {
                                            click: () => {
                                                this.opinion(params.row);
                                            }
                                        }
                                    },
                                    "审核"
                                )
                            ]);
                        }
                    }],
                data: [], // 表单数据
                total: 0 // 表单数据总数
            }
        },
        methods: {
            init() {
                this.getDataList();
            },
            getDataList() {
                this.loading = true;
                creditbankList(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                    }
                });

            },
            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getDataList();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                // 重新加载数据
                this.getDataList();
            },
            edit(v) {
                this.$refs.user.edit();
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "展开";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            selectDateRange(v) {
                if (v) {
                    this.searchForm.startDate = v[0];
                    this.searchForm.endDate = v[1];
                }
            },
            showPic(v) {
                this.fileUrl = v;
                this.picVisible = true;
            },
            exportData(){
                window.location.href = Util.initUrl("/base/common/downloadCredit",this.searchForm);
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getDataList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getDataList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getDataList();
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            edit(v) {

            },
            opinion(v) {
                let query = { isPass: v.isPass, id: v.id, opinion: v.opinion};
                this.$refs.creditbankDrawer.showDrawer(query);
            },
            delAll() {

            }
        },
        mounted() {
            this.init();
        }
    }
</script>
